home *** CD-ROM | disk | FTP | other *** search
- // Send Note External for BBEdit
- // v1.0 ©1993 by Mike Cohen, ISIS International
- // isis@netcom.com
- //
-
- #include "ExternalInterface.h"
- #include <AppleEvents.h>
- #include <Packages.h>
- #include <SetupA4.h>
-
- #define kNoteClass 'IS07'
- #define kChoose 'CHOS'
- #define kSendNote 'SEND'
- #define keyUser 'USER'
-
- pascal void main(ExternalCallbackBlock *cb, WindowPtr w)
- { long selStart, selEnd, firstChar;
- AppleEvent aevt = {0}, reply = {0};
- AEAddressDesc addr = {0};
- char name[256], *p;
- DescType actualType;
- Size actualSize;
- char hstate;
- OSErr err;
- Handle h;
- int i;
-
- RememberA0();
- SetUpA4();
-
- // get text to be sent
- // use ONLY the selection if any, otherwise use the whole thing
- h = (cb->GetWindowContents)(w);
- (cb->GetSelection)(&selStart, &selEnd, &firstChar);
- if (selStart == selEnd)
- {
- selStart = 0;
- selEnd = GetHandleSize(h);
- }
-
- hstate = HGetState(h);
- MoveHHi(h);
- HLock(h);
- p = (*h)+selStart;
-
- // first create an address descriptor for ISIS Notes™
- err = AECreateDesc(typeApplSignature,"IS07",4,&addr);
- if (err == 0)
- {
- // if the text starts with a "To:" line, use that
- if (IUMagIDString(p,"To: ",4,4) == 0)
- {
- i = 1;
- p += 3;
- while (*p == 32)
- ++p;
- while (*p != 13)
- name[i++] = *p++;
- name[0] = i-1;
-
- }
- else
- {
- // otherwise, ask ISIS Notes™ to select a recipient
- if (err = AECreateAppleEvent(kNoteClass,kChoose,&addr,
- kAutoGenerateReturnID,kAnyTransactionID,&aevt)) goto Done;
-
- if (err = AESend(&aevt,&reply,
- kAEWaitReply+kAEAlwaysInteract+kAECanSwitchLayer,
- kAENormalPriority,kNoTimeOut,NULL,NULL)) goto Done;
-
- if (err = AEGetParamPtr(&reply,keyDirectObject,typeChar,
- &actualType,&name[1],255,&actualSize)) goto Done;
-
- name[0] = (actualSize > 255) ? 255 : actualSize;
- AEDisposeDesc(&aevt);
- AEDisposeDesc(&reply);
- }
-
- // now that we have an address, let's send the note
- if (err = AECreateAppleEvent(kNoteClass,kSendNote,&addr,
- kAutoGenerateReturnID,kAnyTransactionID,&aevt)) goto Done;
-
- if (err = AEPutParamPtr(&aevt,keyDirectObject,typeChar,
- (*h)+selStart,selEnd-selStart)) goto Done;
-
- if (err = AEPutParamPtr(&aevt,keyUser,typeChar,&name[1],name[0]))
- goto Done;
-
- err = AESend(&aevt,&reply,kAENoReply,kAENormalPriority,
- kAEDefaultTimeout,NULL,NULL);
- }
-
- Done:
- if (err != 0)
- SysBeep(1);
-
- // it's safe to do this here, since disposing a NULL descriptor is harmless
- AEDisposeDesc(&aevt);
- AEDisposeDesc(&reply);
- AEDisposeDesc(&addr);
-
- HSetState(h,hstate);
- RestoreA4();
- }
-